<template>
  <div>
    <j-search-select-tag
      @change="handleChange"
      v-model="selectValue"
      :dict="tableName+',name,'+tableId"
      :async="true"
      :page-size="20"
      :dict-where="orgCodeVal"
      :placeholder="'请选择所属'+title" />
  </div>
</template>

<script>

  import { orgCodeWhere } from '@/utils/orgCode';

  export default {
    name: 'JSelectUserCode',
    components: {},
    props: {
      orgCode: {
        type: String,
        default: '',
        required: false
      },
      title: {
        type: String,
        default: '用户',
        required: false
      },
      user: {
        type: Boolean,
        default: false,
        required: false
      },
      value: {
        type: String,
        required: false
      },
    },
    data() {
      return {
        tableId: "",
        tableName: "",
        orgCodeVal:'',
        selectValue:null,
      }
    },
    mounted() {
    },
    created() {
      this.getTableName();//获取表名
      this.orgCodeVal = orgCodeWhere(this.orgCode)//获取查询条件
    },
    watch: {
      value:{
        deep:true,
        immediate:true,
        handler(val){
          this.initSelectValue()
        }
      },

    },
    model: {
      prop: 'value',
      event: 'change'
    },

    methods: {
      initSelectValue(){
        this.selectValue = this.value;
      },
      handleChange (selectValue) {
        this.selectValue = selectValue;
        this.callback()
      },
      callback(){
        this.$emit('change', this.selectValue);
      },
      getTableName(){
        this.tableId = this.user?'id':'orgCode';
        this.tableName = this.user?'view_bm_user':'view_bm';
      },

    }
  }
</script>

<style scoped>

</style>